<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
	<title>Distributor Info Management</title>
	<link rel="stylesheet" type="text/css" href="${ctx}/styles/sidecss.css"/>
	<link rel="stylesheet" type="text/css" href="${ctx}/widgets/extremecomponents/extremecomponents.css"/>
	<link rel="stylesheet" type="text/css" href="${ctx}/widgets/My97DatePicker/skin/WdatePicker.css"/>
	<script type="text/javascript" src="${ctx}/widgets/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/WinSollAuto.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/base.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/jsUtil.js?webRoot=${ctx}"></script>
	<script type="text/javascript" src="${ctx}/scripts/highchart/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/button.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/zDrag.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/zDialog.js"></script>
	<%@ include file="/commons/meta.jsp" %>
	<%@ include file="/commons/mdmdialog.jsp"%>
	<script type="text/javascript">
		function query() {
			resetec();
			var from = document.crmPoiInfoForm;
	    		from.submit();
		}
		$(document).ready(function(){
			
			$("#checkAll").click(function(){
				if (this.checked) {
						$(this).attr("checked",false);
						checkboxall();
					}else{
						$(this).attr("checked",true);
						rcheckboxall();
					}
			});
			
			if(${not empty message}){
				alert('fail to save，${message}');
			}
		});
		
		//此全选方法被调用。
		function checkboxall(){
				$("input[type='checkbox']").each(function(){
			          $(this).attr("checked",true);
			    });
	 
			}
		//此全不选方法被调用。
		function rcheckboxall(){
				$("input[type='checkbox']").each(function(){
			          $(this).attr("checked",false);
			    });
	 
			}
		var custExcelImport = function(){
			var diag = new Dialog();
			diag.Width = 500;
			diag.Height = 320;
			diag.Title = "Resource Export";
			diag.URL = "${ctx}/crm/wsCustomerInfo.do?method=excelImportDealer";
			diag.CancelEvent=function(){
				window.location.href="${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=listForDealer";
				diag.close();
			};
			diag.show();
		};
		function batchDelete() {
			var selectedVar = "";
			var chs = $("input[type=checkbox][name=sid]:checked").length;
			if (chs == 0) {
                alert("Please select at least one row of data");
                return;
            } else {
				$('input:checkbox[name="sid"]:checked').each(function(){  
					selectedVar += $(this).val()+"," ;
				});
				if(selectedVar.length>0){
					selectedVar = selectedVar.substring(0,selectedVar.length-1);
					if(confirm("${mr['sfa.common.delete']}")) {
						document.forms[0].ids.value = selectedVar;
						document.forms[0].action = "${ctx}/crm/wsCustomerInfo.do?method=batchDelete";
						document.forms[0].submit();
					}
				}
            }
		}
		function deleteForDealer(customerId){
			var paramData={"customerId":customerId};
			$.post("${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=deleteForDealer",paramData,
					function(data) {
				        if(data != null && data == "0") {
				        	document.forms[0].action = "${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=listForDealer";
							document.forms[0].submit();
				        	//alert("发布成功！");
				        } else if(data != null && data == "-1") {
				        	alert("Please delete the dealer's information and try again！");
				        	return;
				        }
					}
				);
		}

		//批量无效经销商 2018/9/21-fenglangjie
        function changeStatus() {
            debugger
            var selectedVar = "";
            var invalid = 0;
            var chs = $("input[type=checkbox][name=sid]:checked").length;
            if (chs == 0) {
                alert("Please select record");
                return;
            };

            $('input:checkbox[name="sid"]:checked').each(function (index,element) {
                var status = element.parentNode.parentNode.getElementsByTagName('input')[1].value;
				if (status == 0) {
				    invalid = 1;
                    alert("Select include invalid dealer, do not repeat operation");
                    return false;
                }
			});

            $('input:checkbox[name="sid"]:checked').each(function () {
                selectedVar += $(this).val() + ",";
            });
            selectedVar = selectedVar.substring(0, selectedVar.length - 1);

            if (selectedVar.length > 0 && invalid == 0) {
                var reason = prompt("Confirm that you want to modify the current selection" + chs + "Are you sure you want to change the status of the currently selected record to 'invalid'?","Please enter the reason here");
                if (reason) {
                    loading();
                    var url = "${ctx}/crmPoiInfo/crmPoiInfoAction.action?method=invalidPoi";
                    $.ajax({
                        type: "post",
                        url: url,
                        data: {"poiIds": selectedVar, "statusReason": reason},
                        cache: false,
                        success: function (data) {
                            if (data == "1") {
                                alert("Succeeded in changing the status！");
                                query();resetec();
							} else {
                                resetec();
                                alert("Failed to modify the status，Contact the administrator！");
                            }
                        }
                    });
                }
                if (reason !=null && reason == "") {
                    alert("Invalid reasons cannot be empty！");
                }
            }
            return;
        }

		function selectCity(){
			var form=document.forms[0];
			openDialogList('${ctx}','0','provinceCityList',form.cityName.value,form.cityCode.value,'',function(v){
				if(v){
					form.cityName.value=v.text;
					form.cityCode.value=v.id;
				}
			});
		}
		//增加解析poi导出区域excel
		var custExcelOutput = function(){
			var diag = new Dialog();
			diag.Width = 500;
			diag.Height = 120;
			diag.Title = "Data processing";
			 diag.Message = "Data processing,Please wait for data processing, it may take several minutes, please wait";  
			diag.URL = "${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=listForOutputExcel";
			diag.CancelEvent=function(){
				diag.close();
			};
			diag.show();
		};
		//增加解析poi导出区域excel
			var custExcelOutput1 = function(){
			var diag = new Dialog();
			diag.Width = 500;
			diag.Height = 120;
			diag.Title = "Data processing";
			 diag.Message = "Data processing,Please wait for data processing, it may take several minutes, please wait";  
			diag.URL = "${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=listForOutputExcel1";
			diag.CancelEvent=function(){
				
				//window.location.href="${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=listForDealer";
				diag.close();
			};
			diag.show();
			
				//window.location.href="${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=listForOutputExcel";
				
		};
	function myrefresh(){
		window.location.href="${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=listForDealer";
	}
	
	/****************鼠标回车事件****************************/
	document.onkeydown=keyListener;
	function keyListener(e){
	    e = e ? e : event;// 兼容FF
	    if(e.keyCode == 13){
	        query();
	    }
	}
	</script>
</head>
	
<body onLoad="WindowSollAuto()" onResize="WindowSollAuto()">
	<jsp:include page="/commons/messages.jsp" flush="true"></jsp:include>
	<html:form action="/crmPoiInfo/crmPoiInfoAction.do?method=listForDealer" method="post">
	<input type="hidden" id="ids" name="ids"/>
	
	<div class="bosom_one">
		<div class="bosom_top">
			<span class="left"></span>
			<h4><!--TitleStrat-->Distributor Info Management<!--TitleEnd--></h4>
			<div class='MenuList'>
				<!--MenuStrat-->
					<a class="Im80" href="javascript:custExcelImport();">Excel Export</a>
				    <a href="javascript:changeStatus();" class="Im80" >Batch Invalid</a>
					<a href="${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=toAddDealer">add</a>
					<a class="Im80" href="${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=toEditDealerPromotion">Update Promotions</a>
					<a href="javascript:query();" id="query_A">query</a>
					<a href="javascript:myrefresh();">refresh</a>
				<!--MenuEnd-->
			</div>
			<span class="right"></span>
		</div>
		<div class="bosom_side">
			<div class="casing">
				<div class="caput">
					<span class="left"></span><span class="right"></span>
				</div>
				
					<div class="viscera" id="SollAuto">
						<div class="sheet_div">
							<div class="searchbox" id="searchbox">
							<table>
								<tr>
									<td width="1%">Distributor Name</td>
									<td width="1%" align="left"><html:text name="ec" property="$lk_poiName"/></td>
									<td width="1%">User Name</td>
									<td width="1%" align="left"><html:text name="ec" property="$lk_mobile"/></td>
									<td width="1%">Region</td>
									<td width="1%" align="left">
										<html:text name="ec" property="$lk_cityName"/>
									</td>
									<td width="1%">City</td>
									<td width="1%" align="left">
										<html:text name="ec" property="$lk_cityCode"/>
									</td>
									<td width="1%">Address</td>
									<td width="1%" align="left"><html:text name="ec" property="$lk_address"/></td>

									<td width="1%">Support Mobile Payment or not</td>
									<td width="1%">
										<html:select name="ec" property="$eq_payMethods" >
												<html:option value="">Please select</html:option>
												<html:option value="1">yes</html:option>
												<html:option value="0">no</html:option>
											</html:select>
									</td>
									<td width="1%">Review Status</td>
									<td width="1%">
										<html:select name="ec" property="$eq_dealerStatus" >
											<html:option value="">Please select</html:option>
											<html:option value="通过">pass</html:option>
											<html:option value="未通过">not pass</html:option>
										</html:select>
									</td>
									<td width="1%">Support Cash Payment or not</td>
									<td width="1%">
										<html:select name="ec" property="$eq_cashPay" >
											<html:option value="">Please select</html:option>
											<html:option value="1">yes</html:option>
											<html:option value="0">no</html:option>
										</html:select>
									</td>
								  </tr>
								  <tr>
									  <td width="1%">Distributor Code</td>
									  <td width="1%" align="left"><html:text name="ec" property="$lk_poiCode"/></td>
									<td width="1%">Name</td>
									<td width="1%" align="left"><html:text name="ec" property="$lk_nickname"/></td>
									  <td width="1%">Send Coupons Automatically</td>
									  <td width="1%">
										  <html:select name="ec" property="$eq_autoCoupons" >
											  <html:option value="">Please select</html:option>
											  <html:option value="0">yes</html:option>
											  <html:option value="1">no</html:option>
										  </html:select>
									  </td>
									<td class="formTable" width="1%">Customers can be selected</td>
									<td width="1%">
											<html:select name="ec" property="$eq_isEffictive" >
												<html:option value="">Please select</html:option>
												<html:option value="1">Customers can be selected</html:option>
												<html:option value="0">Customers can't selected</html:option>
											</html:select>
									</td>
									  <td width="1%">Status</td>
									  <td width="1%" align="left">
										  <html:select name="ec"  property="$lk_status">
											  <html:option value="">Please select</html:option>
											  <html:option value="1" >Valid</html:option>
											  <html:option value="0">Invalid</html:option>
										  </html:select>
									  </td>

									<td width="1%">Upload the Business License or not</td>
									<td width="1%">
										<html:select name="ec" property="$eq_isUpLoad" >
												<html:option value="">Please select</html:option>
												<html:option value="是">yes</html:option>
												<html:option value="否">no</html:option>
											</html:select>
									</td>
									<td width="1%">Distributor Type</td>
									<td width="1%" >
										<html:select name="ec"  property="$eq_dealerSourceType">
											<c:if test="${not empty dealerSourceTypes}">
												<html:option value="">Please select</html:option>
												<html:optionsCollection name="dealerSourceTypes" label="itemName"
													value="itemName" />
											</c:if>
										</html:select>
									</td>
									<td width="1%">Registration Source</td>
									<td width="1%" >
										<html:select name="ec"  property="$eq_registerSource">
											<html:option value="">Please select</html:option>
											<html:option value="BD提报">BD Submission</html:option>
											<html:option value="APP注册">APP Register</html:option>
											<html:option value="运营维护">Operation Maintenance</html:option>
										</html:select>
									</td>
									
									<td width="1%"></td>
								  </tr>
								<tr>
                                    <td width="1%">A Five-star Distributor or not</td>
                                    <td width="1%">
                                        <html:select name="ec" property="$eq_isFiveStar" >
                                            <html:option value="">Please select</html:option>
                                            <html:option value="1">yes</html:option>
                                            <html:option value="0">no</html:option>
                                        </html:select>
                                    </td>
                                    <td width="1%">Whether a distributor in platform</td>
                                    <td width="1%">
                                        <html:select name="ec" property="$eq_userType" >
                                            <html:option value="">Please select</html:option>
                                            <html:option value="1">yes</html:option>
                                            <html:option value="0">no</html:option>
                                        </html:select>
                                    </td>
                                    <%-- <td width="1%">是否是镇镇通经销商标记</td>
                                    <td width="1%">
                                        <html:select name="ec" property="$eq_isZZTDealerSourceType" >
                                            <html:option value="">Please select</html:option>
                                            <html:option value="1">是</html:option>
                                            <html:option value="0">否</html:option>
                                        </html:select>
                                    </td> --%>
									<td width="1%">Creation Time</td>
									<td colspan="3">
										<html:text property="$ge_created" onclick="WdatePicker({dateFmt:'yyyy-MM-dd','lang':'en'});" readonly="true" styleClass="date_but"></html:text>
										--<html:text property="$le_created" onclick="WdatePicker({dateFmt:'yyyy-MM-dd','lang':'en'});" readonly="true" styleClass="date_but"></html:text></td>
									<td class="formTable" width="1%">With a Business License or not </td>
									<td align="left" width="1%">
										<html:select name="ec" property="$eq_isMatchLicence">
											<html:option value="">Please select</html:option>
											<html:option value="1">yes</html:option>
											<html:option value="0">no</html:option>
										</html:select>
									</td>
									<td class="formTable" width="1%">Date of Signing the Contract </td>
									<td align="left" colspan="2">
										<html:text name="ec" property="$ge_contractDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd','lang':'en'});" readonly="true" styleClass="date_but"></html:text>
										-- <html:text name="ec" property="$le_contractDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd','lang':'en'});" readonly="true" styleClass="date_but"></html:text>
									</td>
									<td align="left" width="1%">Support Bluetooth Printer or not</td>
									<td align="left" width="1%">
										<html:select name="ec" property="$eq_orderBluetoothPrint" >
											<html:option value="">Please select</html:option>
											<html:option value="1">yes</html:option>
											<html:option value="0">no</html:option>
										</html:select>
									</td>
								</tr>
							</table>
						</div>
						<ec:table items="list" var="item" onInvokeAction="query();"
							form="crmPoiInfoForm" retrieveRowsCallback="limit"
							style="width:100%" tableId="ec" locale = "en_US"
							action="${ctx}/crmPoiInfo/crmPoiInfoAction.do?method=listForDealer">
							<ec:exportXls fileName="crmDealerInfo.xls" tooltip="Export Excel" view="xls" />
							<ec:export    fileName="crmDealerInfo.html" tooltip="Export Excel" view="htm" viewResolver="htm" imageName="htm"/>
							<ec:row highlightRow="true">
								<ec:column width="30" title="<input type='checkbox' id='checkAll'/>" property="poiId" sortable="false" viewsDenied="xls,csv,htm" > 
							    	<input type="checkbox" id="sid" name="sid" value="${item.poiId}" />
							    </ec:column>
							     <ec:column property="ROWCOUNT" title="No" ><center>${ROWCOUNT}</center></ec:column>
							     <ec:column property="3" width="1%" title="operation" sortable="false" viewsDenied="xls,csv,htm">
									<center>
										<html:link page="/crmPoiInfo/crmPoiInfoAction.do?method=viewDealer&poiCode=${item.poiCode}">
											<img src="${ctx}/images/view.gif" border="0" alt="detail" />
										</html:link>&nbsp;
										<!-- <a href="javascript:deleteForDealer('${item.poiCode}');" onclick="return confirm('${mr['sfa.common.delete']}')">
											<img src="${ctx}/images/delete.gif" border="0" alt="${mr['sfa.common.button.delete']}" />
										</a> -->
										<html:link page="/crmPoiInfo/crmPoiInfoAction.do?method=initEditDealer&poiId=${item.poiId}">
											<img src="${ctx}/images/edit.gif" border="0" alt="edit" />
										</html:link>&nbsp;
										<html:link page="/crmPoiInfo/crmPoiInfoAction.do?method=toMapDealer&poiId=${item.poiId}">
											<img width=16px height=16px src="${ctx}/images/needleleftyellow.png" border="0" alt="map" />
										</html:link>&nbsp;
										<%-- <c:if test="${empty item.mobile }">
											<html:link page="/crmPoiInfo/crmPoiInfoAction.do?method=deletePoiInfo&id=${item.poiCode}">
												<img width=16px height=16px src="${ctx}/images/delete.gif" border="0" alt="删除" />
											</html:link>
										</c:if> --%>
									</center>
								</ec:column>
							   
								<ec:column property="poiName" title="Distributor Name" />
								<ec:column property="poiCode" title="Distributor Code" />
								<ec:column property="simpleName" title="Distributor Abbreviation" />
								<ec:column property="nickName" title="Name" />
								<ec:column property="mobile" title="User Name" />
								<ec:column property="custTitle" title="Role" />
								<ec:column property="provinceName" title="Region" />
								<ec:column property="cityName" title="City" />
								<ec:column property="areaName" title="District/County" />
								<ec:column property="town" title="Town/Street" />
								<ec:column property="village" title="Village Committee/Neighborhood Committee" />
								<ec:column property="address" title="Distributor Address"></ec:column>
								<ec:column property="1" title="Status"  sortable="false"><input type="hidden" id="poiStatus" name="poiStatus" value="${item.status}" /><c:if test="${item.status eq 1 }">Valid</c:if><c:if test="${item.status eq 0 }">Invalid</c:if></ec:column>
								<ec:column property="2" title="Customers can be selected"  sortable="false" ><c:if test="${item.isEffictive eq 1 || item.isEffictive == null}">Customers can be selected</c:if><c:if test="${item.isEffictive eq 0 }">Customers can't selected</c:if></ec:column>
								<ec:column property="telephone" title="Service Phone Number" />
								<ec:column property="dealerSourceType" title="Distributor Type" />
								<ec:column property="userType" title="Whether a distributor in platform"  sortable="false" ><c:if test="${item.userType eq 1 }">yes</c:if><c:if test="${item.userType eq 0 }">no</c:if></ec:column>
								<%-- <ec:column property="isZZTDealerSourceType" title="是否是镇镇通经销商标记"  sortable="false" >
									<c:if test="${item.isZZTDealerSourceType eq 1 }">
										是
									</c:if>
									<c:if test="${item.isZZTDealerSourceType eq 0 }">
										否
									</c:if>
								</ec:column> --%>
								<ec:column property="registerSource" title="Registration Source" />
								<ec:column property="bussinessRegName" title="Name on Business Registration" />
								<ec:column property="contractDate" format="yyyy-MM-dd" cell="date" title="Date of Signing the Contract" />
								<ec:column property="isMatchLicence" title="With a Business License or not"><center><c:if test="${empty item.isMatchLicence}">no</c:if><c:if test="${item.isMatchLicence eq '0'}">no</c:if><c:if test="${item.isMatchLicence eq '1'}">yes</c:if></center></ec:column>
								<ec:column property="dealerType" title="Distributor Type" cell="com.winchannel.crm.product.renderer.DealerTypeCellRenderer"/>
								<ec:column property="isUpLoad" title="Upload the Business License or not" />
								<ec:column property="handheldIdCardUrl" title="Business License" >
									<center>
										<html:link href="${item.charterUrl}" target="_blank" style="color:#FF0000;">
											<c:if test="${!empty item.charterUrl}">
												<img src="${item.charterUrl}"  alt="${item.charterUrl}" width="40" height="40" border="0" onerror="javascript:this.src='/images/close.png';" />
											</c:if>
										</html:link>
									</center>
								</ec:column>
								<ec:column property="handheldIdCardUrl" title="Contract Photo" >
									<center>
										<html:link href="${item.hxdUrl}" target="_blank" style="color:#FF0000;">
											<c:if test="${!empty item.hxdUrl}">
												<img src="${item.hxdUrl}"  alt="${item.hxdUrl}" width="40" height="40" border="0" onerror="javascript:this.src='/images/close.png';" />
											</c:if>
										</html:link>
									</center>
								</ec:column>
								<ec:column property="handheldIdCardUrl" title="Photo of Holding the ID Card" >
								    <center>
								        <html:link href="${item.handheldIdCardUrl}" target="_blank" style="color:#FF0000;">
								        <c:if test="${!empty item.handheldIdCardUrl}">
								        <img src="${item.handheldIdCardUrl}"  alt="${item.handheldIdCardUrl}" width="40" height="40" border="0" onerror="javascript:this.src='/images/close.png';" />
								        </c:if>
								        </html:link>
								    </center>
								</ec:column>
								<ec:column property="idCardUrl" title="Front Photo of ID Card" >
								    <center>
								        <html:link href="${item.idCardUrl}" target="_blank" style="color:#FF0000;">
								        <c:if test="${!empty item.idCardUrl}">
								        <img src="${item.idCardUrl}"  alt="${item.idCardUrl}" width="40" height="40" border="0" onerror="javascript:this.src='/images/close.png';" />
								        </c:if>
								        </html:link>
								    </center>
								</ec:column>
								<ec:column property="idCardBackUrl" title="Back Photo of ID card" >
								    <center>
								        <html:link href="${item.idCardBackUrl}" target="_blank" style="color:#FF0000;">
								        <c:if test="${!empty item.idCardBackUrl}">
								        <img src="${item.idCardBackUrl}"  alt="${item.idCardBackUrl}" width="40" height="40" border="0" onerror="javascript:this.src='/images/close.png';" />
								        </c:if>
								        </html:link>
								    </center>
								</ec:column>
								<ec:column property="dealerStatus" title="Review Status" />
								<ec:column property="longitude" title="Longitude" />
								<ec:column property="latitude" title="Latitude" />
						<%--		<ec:column property="poiDiestributorName" title="默认送货员" />	--%>
								<ec:column property="payMethods" title="Support Mobile Payment" />
								<ec:column property="orderBluetoothPrint" title="Support Bluetooth Printer or not">
									<center>
								        <c:if test="${item.orderBluetoothPrint eq '0'}">yes</c:if>
										<c:if test="${item.orderBluetoothPrint eq '1'}">no</c:if>
								    </center>
							    </ec:column>
								<ec:column property="cashPay" title="Support Cash Payment" />
                                <ec:column property="isFiveStar" title="A Five-star Distributor or not">
                                    <center>
                                        <c:if test="${item.isFiveStar eq 1}">yes</c:if>
                                        <c:if test="${item.isFiveStar eq 0}">no</c:if>
                                    </center>
                                </ec:column>
								<ec:column property="minOrderAmount" title="MIN Order Amount" />
								<ec:column property="statusReason" title="Reason for Validness/Invalidness" />
								<ec:column property="created" format="yyyy-MM-dd HH:mm:ss" cell="date" title="Creation Time" />
								<ec:column property="updated" format="yyyy-MM-dd HH:mm:ss" cell="date" title="Last Update Time" />
							</ec:row>
						</ec:table>
					</div>
				</div>
				<div class="trail">
					<span class="fleft"></span><span class="fright"></span>
				</div>
			</div>
		</div>
		<div class="bosom_bottom">
			<span class="left"></span><span class="right"></span>
		</div>
	</div>
	</html:form>
</body>
</html>